from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField
from wtforms.validators import DataRequired, Length, AnyOf, Optional, EqualTo
from flask_wtf.file import FileField, FileRequired, FileAllowed


class BaseForm(FlaskForm):
    class Meta:
        csrf = False


class TokenForm(BaseForm):
    grant_type = StringField('授权类型', validators=[DataRequired('类型不能为空')])
    username = StringField('账号', validators=[DataRequired('账号不能为空'), Length(1, 255)])
    password = StringField('密码', validators=[DataRequired('密码不能为空'), Length(1, 255)])


class UserResetPassword(BaseForm):
    password = StringField('确认密码', validators=[DataRequired('密码不能为空'), Length(1, 255)])
    new_password = StringField('新密码', validators=[DataRequired('新密码不能为空'), Length(6, 255), EqualTo('new_password2', message="必须与确认密码一致")])
    new_password2 = StringField('新密码2', validators=[DataRequired('确认新密码不能为空'), Length(6, 255)])


class UserUpdateCompany(BaseForm):
    cid = IntegerField('单位', validators=[DataRequired('单位不能为空')])


class CodeForm(BaseForm):
    tel = StringField('手机号', validators=[DataRequired('必填'), Length(1, 20)])


class ValidateCodeForm(BaseForm):
    tel = StringField('手机号', validators=[DataRequired('必填'), Length(1, 20)])
    code = StringField('验证码', validators=[DataRequired('必填'), Length(1, 6)])


class ArticleAuditForm(BaseForm):
    audit_status = StringField('文章状态', validators=[DataRequired('必填'), AnyOf([7, 8, 9, 10], message="状态不是有效的数值")])


class AttachmentForm(BaseForm):
    url = StringField('图片地址', validators=[DataRequired('必填'), Length(1, 255)])


class FileUploadForm(BaseForm):
    upload = FileField('图片', validators=[FileRequired(), FileAllowed(['jpg', 'png', 'jpeg', 'gif'], '只允许上传图片')])
